/*
 * CSessionEntity.h
 *
 *  Created on: 2011-9-7
 *      Author: stargui
 */

#ifndef CSESSIONENTITY_H_
#define CSESSIONENTITY_H_

#include <iostream>
//#include <CommonLibrary.h>
#include "../Adapter/CStreamLayer.h"
#include "CProtocolFactory.h"
#include "../SocketUtils/CMutexUtils.h"
#include "ProtocolLabel.h"
//#include "CSessionManager.h"
#include "ConfigJsonKeyword.h"
#include "Base.h"
#include "Mediastream.h"
using namespace PROTOCOL;

class CSessionEntity
{

public:

	CSessionEntity();

	virtual ~CSessionEntity();

public:

	int InsertSessionTask(unsigned int taskindex,int taskHandle, std::string taskName,void *_threadid);

	bool RemoveSessionTask(unsigned int taskindex);

	bool ActiveReleaseTask();

	bool HandleSessionRequest(Json::Value &request);

	bool HandleSessionTask(int taskHandle, CProtocolFactory *packet);

	void SetTaskCallback(boost::function<bool(unsigned int,unsigned int, Json::Value &,int,void *)> callback);

	void QuerySessionTask(unsigned int taskindex,int& status);


public:

	bool passiveMode;//ture:passive ;flase:initiative

	unsigned int markedIndex;//index����

	int sessionHandle;//socket

	int sessionstatus;//0�����ߣ�1������

	int sessionlevel;//�û��ȼ� 3����ͨ�û���2������Ա��1�������û�

	int loginstyle;//���뷽ʽ//0:Ĭ�ϣ�1��û���û����ֶΣ�����Ա��

	std::string clientip;//�ͻ���ip

	std::string username;//�ͻ��˵����û���

	std::string password;//�û�����

	std::string clientmac;//�ͻ���mac

	datetime_t logintime;	//����utcʱ��

private:

	bool TaskCallback(unsigned int source,unsigned int taskindex, Json::Value &response,int type);

	bool SearchSessionTask(std::string taskName, unsigned int &taskindex);

	bool OnRequestDownVideo(Json::Value & request);

	bool OnControlDownVideo(Json::Value & request);

	bool OnRequestRemotePlayback(Json::Value & request);

	bool OnControlRemotePlayback(Json::Value & request);


private:



private:

	std::map<unsigned int, CStreamLayer *> _task;

// 	std::map<std::string, CRealStream* > _handleRealstream;

	std::map<std::string, boost::function<bool(Json::Value &)> > _operation;

	boost::function<bool(unsigned int,unsigned int, Json::Value &,int,void *)> _sessionCallback;


};

#endif /* CSESSIONENTITY_H_ */
